package cn.xxm.dongbao.user.config.nacos;

import com.alibaba.cloud.nacos.registry.NacosRegistration;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

//@Component
@Configuration
public class ServiceIDConfig {
    private NacosRegistration registration;
    private static String serviceId;

    public ServiceIDConfig(NacosRegistration registration) {
        this.registration = registration;
    }

    @PostConstruct
    public void initServiceInfo() throws Exception {
        registration.getMetadata().put("service.id", UUID.randomUUID().toString());
        registration.getMetadata().put("startup.time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        registration.getMetadata().put("server.ip", WebToolUtils.getLocalIP());

    }
}